<template>
	<view class="add_comm">
		<view class="add_comm_title">小区信息</view>
		<view class="ele_title_left bg-white padding-left-sm padding-bottom-xs">
			<view class="ele_title_inner padding-xs">{{info.residential_quarters_name}}</view>
			<view class="ele_address">
				<image class="ele_address_img" src="../../../common/img/dizhi_hui.png" mode=""></image>
				<text>{{info.residential_quarters_address}}</text>
			</view>
		</view>
		<view class="add_comm_title">网关信息</view>
		<view class="add_box">
			<view class="add_inner">
				<view class="add_inner_text">网关编号</view>
				<input class="add_inner_input" type="text" value="" @input="num" placeholder="请输入设备编号" />
			</view>
			<view class="add_inner">
				<view class="add_inner_text">网关备注</view>
				<input class="add_inner_input" type="text" value="" @input="rema" placeholder="请输入网关备注" />
			</view>
		</view>
		<view class="add_text_btn" @tap="addInfo" >保存</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				info:'',
				residential_quarters_guid:'',//	字符串	小区标识	是
				gateway_sn:'',//	字符串	网关SN	是
				remark:'',//	字符串	备注	否
			}
		},
		onLoad(options) {
			let info=JSON.parse(options.item);
			this.info=info;
		},
		methods: {
			num(e){
				this.gateway_sn = e.detail.value;
			},
			rema(e){
				this.remark = e.detail.value;
			},
			addInfo(){
			  
			   if(this.gateway_sn.trim()=='' || this.gateway_sn.trim()==null){
					uni.showToast({
						icon: 'none',
						title: '网关编号不能为空'
					});
					return;
			   }
			   let that=this;
			   that.http.tokenreq({
					url: 'gateway/v1/bind',
					data:{
						"residential_quarters_guid":this.info.residential_quarters_guid,
						"gateway_sn":this.gateway_sn,
						"remark":this.remark
					}
			   }).then((res) => {
			   	let e=res.data;
			   	if(e.code==0 && e.success){
			   		uni.showModal({
			   			content: e.message,
			   			showCancel:false,
			   			success: function (res) {
			   				if (res.confirm) {
			   					uni.redirectTo({
			   						url: '/pages/gateway/gatewayList/gatewayList?item='+JSON.stringify(info)
			   					})
			   				}
			   			}
			   		});
			   	}else{
			   		uni.showToast({
			   			icon: 'none',
			   		    title: e.message
			   		});
			   	}
			   })
			}
		}
	}
</script>
